
// out vec4 gl_FragColor;
// in vec2 gl_FragCoord;

#ifdef GL_ES
precision mediump float;
#endif

#define PI 3.1415926535
#define PIXEL.05
#define AA 2

uniform vec2 u_mouse;
uniform vec2 u_resolution;
uniform float u_time;

//画布
vec2 FixUV(vec2 coord,float num){
    //画布原点移动到中央  并且不随外部画布拉伸
    //默认以短轴为基准 num=1.0
    vec2 uv=num*(2.*coord.xy-u_resolution)/
    min(u_resolution.x,u_resolution.y);
    return uv;
}

float sdfCircle(in vec2 p,float r){
    return length(p)-r;
}
float sdfRect(in vec2 p , vec2 b){
    vec2 d = abs(p)-b; 
    return length(max(d,0.))+min(max(d.x,d.y),0.); 
}

void main(){ 
    
    vec2 uv=FixUV(gl_FragCoord.xy,2.);
    vec3 color=vec3(.5); 
    
    vec2 rect = vec2(1.5*sin(u_time*.1),1.3*sin(u_time*.1));

    float d = sdfRect(uv,rect);
    color=1.-sign(d)*vec3(.4,.5,.6);
    color*=1.-exp(-3.*abs(d));
    color*=.8+.2*sin(150.*abs(d));
    color=mix(color,vec3(1.),smoothstep(.005,.004,abs(d)));
    
    //   if(iMouse.z>1. ){ }

    vec2 m=FixUV(u_mouse.xy,2.);
    float mdis= sdfRect(uv,rect);;
    mdis=abs(mdis);
    color=mix(color,vec3(.9216,.6039,.0902),
    smoothstep(.02,.01,abs(length(uv-m)-mdis)));
    color=mix(color,vec3(.902,.5176,.0824),
    smoothstep(.05,.03,abs(length(uv-m))) );
    // color *=vec3(u_mouse.button,1.,2.);

    gl_FragColor=vec4(color,1.);

}